package com.ruoyi.web.controller.clockin;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ClockIn;
import com.ruoyi.service.IClockInService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 打卡功能Controller
 * 
 * @author ruoyi
 * @date 2020-06-17
 */
@Controller
@RequestMapping("/ruoyi/in")
public class ClockInController extends BaseController
{
    private String prefix = "ruoyi/in";

    @Autowired
    private IClockInService clockInService;

    @RequiresPermissions("ruoyi:in:view")
    @GetMapping()
    public String in()
    {
        return prefix + "/in";
    }

    /**
     * 查询打卡功能列表
     */
    @RequiresPermissions("ruoyi:in:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClockIn clockIn)
    {
        startPage();
        List<ClockIn> list = clockInService.selectClockInList(clockIn);
        return getDataTable(list);
    }

    /**
     * 导出打卡功能列表
     */
    @RequiresPermissions("ruoyi:in:export")
    @Log(title = "打卡功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClockIn clockIn)
    {
        List<ClockIn> list = clockInService.selectClockInList(clockIn);
        ExcelUtil<ClockIn> util = new ExcelUtil<ClockIn>(ClockIn.class);
        return util.exportExcel(list, "in");
    }

    /**
     * 新增打卡功能
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存打卡功能
     */
    @RequiresPermissions("ruoyi:in:add")
    @Log(title = "打卡功能", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClockIn clockIn)
    {
        //获取当前用户的登录名自动提交
        String name = ShiroUtils.getLoginName();
        clockIn.setcName(name);
        return toAjax(clockInService.insertClockIn(clockIn));
    }

    /**
     * 修改打卡功能
     */
    @GetMapping("/edit/{cId}")
    public String edit(@PathVariable("cId") Long cId, ModelMap mmap)
    {
        ClockIn clockIn = clockInService.selectClockInById(cId);
        mmap.put("clockIn", clockIn);
        return prefix + "/edit";
    }

    /**
     * 修改保存打卡功能
     */
    @RequiresPermissions("ruoyi:in:edit")
    @Log(title = "打卡功能", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClockIn clockIn)
    {
        return toAjax(clockInService.updateClockIn(clockIn));
    }

    /**
     * 删除打卡功能
     */
    @RequiresPermissions("ruoyi:in:remove")
    @Log(title = "打卡功能", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clockInService.deleteClockInByIds(ids));
    }
}
